<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
  <th:block th:include="include :: header('采购订单审核')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
  <form class="form-horizontal m" id="form-order-audit">
    <input type="hidden" name="orderId" id="orderId">

    <div class="col-xs-12">
      <div class="form-group">
        <label class="col-sm-3 control-label">订单编号：</label>
        <div class="col-sm-8">
          <input id="orderCode" class="form-control" type="text" readonly>
        </div>
      </div>
    </div>

    <div class="col-xs-12">
      <div class="form-group">
        <label class="col-sm-3 control-label">供应商名称：</label>
        <div class="col-sm-8">
          <input id="supplierName" class="form-control" type="text" readonly>
        </div>
      </div>
    </div>

    <div class="col-xs-12">
      <div class="form-group">
        <label class="col-sm-3 control-label">采购日期：</label>
        <div class="col-sm-8">
          <input id="orderDate" class="form-control" type="text" readonly>
        </div>
      </div>
    </div>

    <div class="col-xs-12">
      <div class="form-group">
        <label class="col-sm-3 control-label">订单总金额：</label>
        <div class="col-sm-8">
          <input id="totalAmount" class="form-control" type="text" readonly>
        </div>
      </div>
    </div>

    <div class="col-xs-12">
      <div class="form-group">
        <label class="col-sm-3 control-label is-required">审核结果：</label>
        <div class="col-sm-8">
          <div class="radio-box">
            <label>
              <input type="radio" name="auditResult" value="1" checked> 通过
            </label>
            <label>
              <input type="radio" name="auditResult" value="2"> 不通过
            </label>
          </div>
        </div>
      </div>
    </div>

    <div class="col-xs-12">
      <div class="form-group">
        <label class="col-sm-3 control-label is-required">审核意见：</label>
        <div class="col-sm-8">
          <textarea name="auditOpinion" class="form-control" required></textarea>
        </div>
      </div>
    </div>
  </form>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
  var prefix = ctx + "purchase/order";

  // 初始化表单验证
  $("#form-order-audit").validate({
      focusCleanup: true,
      rules: {
          auditOpinion: {
              required: true
          }
      }
  });

  // 提交审核
  function submitAudit() {
      if ($.validate.form()) {
          var data = {
              orderId: $("#orderId").val(),
              orderCode: $("#orderCode").val(),
              auditResult: $("input[name='auditResult']:checked").val(),
              auditOpinion: $("textarea[name='auditOpinion']").val()
          };

          $.operate.save(prefix + "/audit", data);
      }
  }

  // 加载订单数据
  function loadOrderData(orderId) {
      $.ajax({
          url: prefix + "/" + orderId,
          type: "get",
          success: function(result) {
              if (result.code == 200) {
                  var data = result.data;
                  $("#orderId").val(data.orderId);
                  $("#orderCode").val(data.orderCode);
                  $("#supplierName").val(data.supplierName);
                  $("#orderDate").val($.common.dateFormat(data.orderDate));
                  $("#totalAmount").val(data.totalAmount);
              }
          }
      });
  }
</script>
</body>
</html>